package UI;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JScrollPane;

import COMP.ImageComponent;
import COMP.RadarChart;
import COMP.imgBtn;

public class PopUp3DChart extends JDialog{
	private imgBtn btnOpenTable = new imgBtn("Img/detail_chart.png","Img/detail_chart_click.png");
	private imgBtn btnClose = new imgBtn("Img/butt_close.png");
	private imgBtn btnWindowsClose = new imgBtn("Img/chart_butt_x.png");
	private imgBtn btnWindowsIconified = new imgBtn("Img/chart_butt_-.png");
	private ImageComponent bg = new ImageComponent(new ImageIcon("Img/pentagon.png").getImage());
	private RadarChart chart = new RadarChart(null);
	private JFrame frmHsproject;
	JScrollPane remarkJSP = chart.getRemarks();
	public PopUp3DChart(JFrame frmHsproject, JDialog superclass){
		super(superclass);
		this.frmHsproject = frmHsproject;
		init();
	}
	public void init(){
		setSize(900, 700);
		setLocationRelativeTo(null);
		getContentPane().setLayout(null);
		this.setUndecorated(true);
		addChart();
		addBtn();
		bg.setBounds(0,0,900,700);
		getContentPane().add(bg);
	}
	private void addChart(){
//		Chart3D chartNPV = new Chart3D(null,null,null,null);
//		chartNPV.setBounds(15,10,550,400);
//		getContentPane().add(chartNPV);
		
		chart.setBounds(38,76,824,534);
		chart.setChartSize(824, 534);
		chart.setY_INIT(305);
		chart.setX_INIT(400);
		chart.repaintChart();
		getContentPane().add(chart);
		
		remarkJSP.setBounds(0,45,250,45);
	}
	private void addBtn(){
		btnOpenTable.setBounds(762,655,78,28);
		btnOpenTable.chageRolloverImage();
		getContentPane().add(btnOpenTable);
		btnClose.setBounds(860,655,28,28);
		getContentPane().add(btnClose);
		btnWindowsClose.setBounds(880,7,10,10);
		btnWindowsClose.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent arg0) {
				closePopUp();
			}
			
		});
		getContentPane().add(btnWindowsClose);
		btnWindowsIconified.setBounds(868, 7, 10, 10);
		btnWindowsIconified.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				frmHsproject.setExtendedState(JFrame.ICONIFIED); 
			}

		});
		getContentPane().add(btnWindowsIconified);
	}
	public void closePopUp(){
		this.dispose();
	}
	public void eventbtnOpenTable(ActionListener e){
		btnOpenTable.addActionListener(e);		
	}
	public void eventbtnClose(ActionListener e){
		btnClose.addActionListener(e);		
	}
	public void setData(ArrayList<double[]> data){
		chart.setData(data);
		chart.repaintChart();
		this.repaint();
	}
	public void setDataLabel(String[] dataLabel){
		chart.setDataLabel(dataLabel);
		remarkJSP = chart.getRemarks();
	}
	public void removeChart(){
		chart.removeChart();
	}
	public void repaintChart(){
		chart.repaintChart();
		remarkJSP = chart.getRemarks();
		remarkJSP.setBorder(null);
		remarkJSP.setBounds(0,45,250,45);
		chart.add(remarkJSP);
	}
	public void anmationChart(){
		Thread thr = new Thread(chart);
		thr.start();
		repaintChart();
	}
	public RadarChart getRadarChart(){
		return chart;
	}
	
	public void drawAxisName(){
		chart.drawAxisName();
	}
	
	public void setOpaque(boolean flag){
		chart.setOpaque(flag);
	}
	
}
